package com.lnu_devteam.zongce.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lnu_devteam.zongce.annotation.AuthCheck;
import com.lnu_devteam.zongce.common.BaseResponse;
import com.lnu_devteam.zongce.common.ErrorCode;
import com.lnu_devteam.zongce.common.PageRequest;
import com.lnu_devteam.zongce.common.ResultUtils;
import com.lnu_devteam.zongce.exception.BusinessException;
import com.lnu_devteam.zongce.model.dto.FixedProjectSaveDTO;
import com.lnu_devteam.zongce.model.dto.FixedProjectUpdateDTO;
import com.lnu_devteam.zongce.model.enums.RoleEnum;
import com.lnu_devteam.zongce.model.vo.FixedProjectVO;
import com.lnu_devteam.zongce.service.FixedProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xbaozi
 * @version 1.0
 * @classname FixedProjectController
 * @date 2023-03-23  15:24
 * @description 固定分值项目接口
 */
@Api(value = "/fixed", tags = {"固定分值项目接口"})
@RestController
@Slf4j
@RequestMapping("/fixed")
public class FixedProjectController {
    @Resource
    private FixedProjectService fixedProjectService;

    /**
     * @param fixedProjectSaveDTO 指定固定项目加分相关参数
     * @return BaseResponse<Boolean>
     * @description 新增固定项目加分
     * @author xbaozi
     * @date 2023/3/29 21:17
     **/
    @ApiOperation(value = "新增固定项目加分*/", notes = "新增固定项目加分*/", httpMethod = "POST")
    @PostMapping("/save")
    @AuthCheck(anyRole = {RoleEnum.ADMIN, RoleEnum.SUPER})
    public BaseResponse<Boolean> saveFixedProject(@RequestBody FixedProjectSaveDTO fixedProjectSaveDTO) {
        if (fixedProjectSaveDTO == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        boolean res = fixedProjectService.saveFixedProject(fixedProjectSaveDTO);
        return ResultUtils.success(res);
    }

    /**
     * @param fixedProjectUpdateDTO 指定固定项目加分相关参数
     * @return BaseResponse<Boolean>
     * @description 更新固定项目加分
     * @author xbaozi
     * @date 2023/3/29 21:26
     **/
    @ApiOperation(value = "更新固定项目加分*/", notes = "更新固定项目加分*/", httpMethod = "POST")
    @PostMapping("/update")
    @AuthCheck(anyRole = {RoleEnum.ADMIN, RoleEnum.SUPER})
    public BaseResponse<Boolean> updateFixedProject(@RequestBody FixedProjectUpdateDTO fixedProjectUpdateDTO) {
        if (fixedProjectUpdateDTO == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        boolean res = fixedProjectService.updateFixedProject(fixedProjectUpdateDTO);
        return ResultUtils.success(res);
    }

    /**
     * @param pageRequest   分页请求参数
     * @return BaseResponse<Page < FixedProjectVO>>
     * @description 分页获取
     * @author xbaozi
     * @date 2023/3/29 22:29
     **/
    @ApiOperation(value = "分页获取", notes = "分页获取", httpMethod = "GET")
    @GetMapping("/page")
    public BaseResponse<Page<FixedProjectVO>> pageFixedProject(PageRequest pageRequest) {
        if (pageRequest == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        Page<FixedProjectVO> page = fixedProjectService.pageVO(pageRequest);
        return ResultUtils.success(page);
    }

    /**
     * @return BaseResponse<List < FixedProjectVO>>
     * @description 获取所有固定加分项
     * @author xbaozi
     * @date 2023/3/29 22:53
     **/
    @ApiOperation(value = "获取所有固定加分项", notes = "获取所有固定加分项", httpMethod = "GET")
    @GetMapping("/list")
    public BaseResponse<List<FixedProjectVO>> listFixedProject() {
        List<FixedProjectVO> resList = fixedProjectService.listAll();
        return ResultUtils.success(resList);
    }

    /**
     * @param fpId 固定加分项目ID
     * @return BaseResponse<Boolean>
     * @description 通过固定加分项目ID删除对应记录
     * @author xbaozi
     * @date 2023/3/30 22:51
     **/
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "long", name = "fpId", value = "固定加分项目ID", required = true)
    })
    @ApiOperation(value = "通过固定加分项目ID删除对应记录", notes = "通过固定加分项目ID删除对应记录", httpMethod = "POST")
    @PostMapping("/delete")
    @AuthCheck(anyRole = {RoleEnum.ADMIN, RoleEnum.SUPER})
    public BaseResponse<Boolean> deleteFixedProject(Long fpId) {
        boolean res = fixedProjectService.deleteFixedProject(fpId);
        return ResultUtils.success(res);
    }

}
